<?php
namespace app\models;

use mvc\web\Model;

class MobileBorrow extends Model
{
    public static function tableName()
    {
        return 'mobile_borrow';
    }

    public function rules()
    {
        return [
            'mobile_id' => [
                'required',
            ],
            'borrow_user' => [
                'required',
                [
                    'string',
                    'min' => 2,
                    'max' => 8,
                ],
            ],
            'borrow_time' => [
               'date'
            ],
            'should_return_time' => [
                'date'
            ],
            'actual_return_time' => [
                'date'
            ],
        ];
    }

    public function labels()
    {
        return [
            'mobile_id' => '手机ID',
            'borrow_user' => '借用人',
            'borrow_time' => '借用时间',
            'should_return_time' => '应该归还时间',
            'actual_return_time' => '实际归还时间',
            'status' => '归还状态',
        ];
    }

    public static function status($key = null)
    {
        $arr = [
            '0' => '借用中',
            '1' => '已归还'
        ];
        return $key !== null ? (isset($arr[$key]) ? $arr[$key] : '') : $arr;
    }

    public static function os($key = null)
    {
        $arr = [
            '1' => 'IOS',
            '2' => 'Android',
            '3' => 'Windows Phone'
        ];
        return $key !== null ? (isset($arr[$key]) ? $arr[$key] : '') : $arr;
    }
}